package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/rechargeInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoApiController {

	@Autowired
	private RechargeInfoService rechargeInfoService;

	@GuiGuLogin
	@Operation(summary = "提交充值")
	@PostMapping("submitRecharge")
	public Result<Map<String,String>> submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo){
		String orderNo = rechargeInfoService.submitRecharge(rechargeInfoVo);
		Map<String,String> map = new HashMap<>();
		map.put("orderNo",orderNo);
		return Result.ok(map);
	}

	@Operation(summary = "根据订单号查询充值记录")
	@GetMapping("getByOrderNo/{orderNo}")
	public Result<RechargeInfo> getByOrderNo(@PathVariable("orderNo") String orderNo){
		RechargeInfo rechargeInfo = rechargeInfoService.getByOrderNo(orderNo);
		return Result.ok(rechargeInfo);
	}
}

